<?php
if (!class_exists('UserDao')) {
	/**
	 *  Propel DAO class for user operations
	 *	@author Alecsandru Gabriel DINU
	 *  @since Jun 27, 2008
	 * 
	 *  @Bean(id = "userDao") 
	 */
	class UserDao extends BaseDao {

		/**
		 * Saves a user in the database with Propel.
		 * @access public
		 * @param User
		 * @return integer Number of affected rows
		 * @throws  ResourceAlreadyExistsException
		 */
		public function save($user) {
			try {
				return $user->save();
			} catch (PropelException $e) {
				throw new ResourceAlreadyExistsException($e);	
			}
		}
		
		/**
		 * Gets a user from the database based on his id
		 * @access public
		 * @param integer User id
		 * @return User
		 */
		public function get($id) {
			return UserPeer::retrieveByPK($id);
		}
		
		/**
		 * Gets all the users from the database
		 * @access public
		 * @return array
		 */
		public function getAll($onlyActive = true) {
			$c = new Criteria();
			if ($onlyActive) {
				$c->add(UserPeer::ACTIVE, 1);
			}	
			return UserPeer::doSelect($c);
		}

		/**
		 * Gets a user from the database based on his email
		 * @access public
		 * @param string E-mail address
		 * @return User
		 */
		public function loadByEmail($email) {
			$c = new Criteria();
			$c->add(UserPeer::EMAIL, $email);
			$c->add(UserPeer::ACTIVE, 1);
			return UserPeer::doSelectOne($c);
		}
	}
}
?>